home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / libexec / kernel / grub-ins.pl < prev    next >
Encoding:
Perl Script  |  2002-11-11  |  2.4 KB  |  86 lines

  1. #!/usr/bin/perl
  2. # $Id: grub-ins.pl,v 1.7 2000/07/11 12:39:41 duwe Exp $
  3.  
  4. $nam = $insimage = $ARGV[0];
  5. $nam =~ s/\.//g;
  6.  
  7. open (BGML, "</boot/grub/menu.lst") || die;
  8.  
  9. # Determine if this is a true Pentium or better and we can use that kernel,
  10. # and if we need to disable SMP (for AMD, Cyrix, ...). Set failsafe defaults.
  11. $apic = " noapic nosmp";
  12. $pc97 = "";
  13. if (open(CI, "</proc/cpuinfo")) {
  14.   while(<CI>) {
  15.     m/^\s*flags\s*:.* fpu\b.* tsc\b/ && ($pc97 = "-pc97");
  16.     m/^\s*flags\s*:.* apic\b/ && ($apic = "");
  17.   }
  18.   close CI;
  19. }
  20.  
  21. # Now let's see whether we need an initrd for the current root.
  22. $thisroot = `/usr/sbin/rdev`;
  23. $thisroot =~ s/\s.*$//sm;
  24. $initrd = "\ninitrd = /boot/initrd-$insimage.gz\n";
  25. ($thisroot =~ m,^/dev/hd, ) && ( $initrd = "" );
  26.  
  27. $secret = "no";
  28. $otherimg = "";
  29. # Write it out just before the first "title=" entry (if there is one)
  30. while (<BGML>) {
  31.   if (m/^\s*password\s*=/i) { $secret = "yes"; }
  32.   s/^\s*title\s*=\s*oldlinux\s*$/title = Linux-cruft$$\n/i; #the best we can do
  33.   s/^\s*title\s*=\s*desktop.lx\s*linux\s*$/title = OldLinux\n/i;
  34.   if (m/^\s*title\s*/) { $otherimg = $_; last; }
  35.   print;
  36. }
  37.  
  38. $vga = "";
  39. if (open(ESC, "</etc/system.cnf")) {
  40.   while(<ESC>) {
  41.     m/^\s*CONF_GRAPHIC_CARD1_VESAMODE\s*=\s*"?(\w+)/ && ($vga = "$1");
  42.   }
  43.   close ESC;
  44. }
  45. $vga = "274" if ($vga eq "");
  46.  
  47. # try to figure out the boot partition ("slice").
  48. if (open(FSTAB, "</etc/fstab")) {
  49.   while(<FSTAB>) {
  50.     m,^\s*(/dev/[\S]+)\s*/boot\s, && ($bootslice = $1);
  51.   }
  52.   close FSTAB;
  53. }
  54. $bootslice = $thisroot unless $bootslice;
  55. $bootslice =~ s,\s*(/dev/.d.),,;
  56. $bootdisk  = $1;        # what we just cut off: device w/o partition
  57. $bootslice = $bootslice - 1;
  58.  
  59. $biosdisk = "hd0";        # default: first disk
  60. if (open(DEVMAP, "</boot/grub/device.map")) {
  61.   while(<DEVMAP>) {
  62.     m,^\s*\((\w+)\)\s*$bootdisk, && ($biosdisk = $1);
  63.   }
  64.   close DEVMAP;
  65. }
  66.  
  67. # Now write the new entry
  68. print "title  = Desktop/LX\n";
  69. print "root   = ($biosdisk,$bootslice)\n";
  70. print "kernel = /boot/vmlinuz$pc97-$insimage-modular vga=$vga$apic quiet";
  71. print " console=ttyS3,9600 apm=off acpi=no-idle";
  72. print " root=$thisroot" unless ($thisroot eq "");
  73. print "$initrd\n";
  74.  
  75. # and now dump the remaining input file
  76. print $otherimg;
  77. while (<BGML>) {
  78.   if (m/^\s*password\s*=/i) { $secret = "yes"; }
  79.   s/^\s*title\s*=\s*oldlinux\s*$/title = Linux-cruft$$\n/i; #the best we can do
  80.   s/^\s*title\s*=\s*desktop.lx\s*linux\s*$/title = OldLinux\n/i;
  81.   print;
  82. }
  83. close BGML;
  84.  
  85. chmod 0600, "/proc/self/fd/1" unless ($secret eq "no");
  86.